package modelLayer;

import java.util.ArrayList;

public class PersonContainer {
    
    private ArrayList<Person> persons;
    private static PersonContainer instance;
    
    private PersonContainer() {
        persons = new ArrayList<Person>();
    }
    
    public static PersonContainer getInstance() {
        if (instance == null) {
            instance = new PersonContainer();
        }
        
        return instance;
    }
    
    public void addPerson(Person person) {
        persons.add(person);
    }
    
    public Person findPerson(String phone) {
        boolean found = false;
        int index = 0;
        while(index < persons.size() && !found) {
            Person p = persons.get(index);
            if(p.getPhone().equals(phone)) {
                found = true;
            }
            else {
                index++;
            }
        }
        
        if(found) {
            return persons.get(index);
        }
        else {
            return null;
        }
    }
    
    public void removePerson(Person p) {
        persons.remove(p);
    }
}
